<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(comds) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("/var/www/log/comds/aa", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);


    $id = $arr2["TotalExp"];
    $id2 = $arr2["FirstLoginTime"];
    $id3 = $arr2["TotalDollorGet"];
    $id4 = $arr2["TodayGameTime"];
    $id5 = $arr2["TodayTCrystalLose"];
    $id6 = $arr2["Crystal"];
    $id7 = $arr2["TodayGoldGet"];
    $id8 = $arr2["TodayGoldLose"];
    $id9 = $arr2["Cracked"];
    $id10 = $arr2["WeaponList"];

    $id11 = $arr2["TodayExp"];  //2
    $id12 = $arr2["TodayIapInfo"];
    $arr3 = json_decode($id12, true);
     $id12a = $arr3["com.trinitigame.callofminibulletdudes.099cents1"];
      $id12b = $arr3["com.trinitigame.callofminibulletdudes.099cents2"];
       $id12c = $arr3["com.trinitigame.callofminibulletdudes.new499cents1"];
        $id12d = $arr3["com.trinitigame.callofminibulletdudes.new499cents2"];
         $id12e = $arr3["com.trinitigame.callofminibulletdudes.new999cents1"];
          $id12f = $arr3["com.trinitigame.callofminibulletdudes.new999cents2"];
           $id12g = $arr3["com.trinitigame.callofminibulletdudes.new1999cents1"];
            $id12h = $arr3["com.trinitigame.callofminibulletdudes.new1999cents2"];
             $id12i = $arr3["com.trinitigame.callofminibulletdudes.new4999cents1"];
              $id12j = $arr3["com.trinitigame.callofminibulletdudes.new4999cents2"];
    $id13 = $arr2["Gold"];
    $id14 = $arr2["Level"];
    $id15 = $arr2["GameActiveTime"]; //3
    $id16 = $arr2["TotalGoldGet"];
    $id17 = $arr2["UILastId"];
    $id18 = $arr2["HireoutSelfTimes"];
    $id19 = $arr2["TotalGameTime"]; //4
    $id20 = $arr2["TodayTCrystalGet"];


    $id21 = $arr["deviceid"];
    $id22 = $arr["gamename"];
    //$id23 = $arr["whatday"];
    $id24 = $arr["createdate"];

    $id25 = $arr2["UIEnterInfo"];
    $arr4 = json_decode($id25, true);
         $id25a = $arr4["10"];
      $id25b = $arr4["21"];
       $id25c = $arr4["22"];
        $id25d = $arr4["23"];
         $id25e = $arr4["24"];
          $id25f = $arr4["31"];
           $id25g = $arr4["41"];
            $id25h = $arr4["42"];
             $id25i = $arr4["50"];
              $id25j = $arr4["60"];
             $id25k = $arr4["71"];
            $id25l = $arr4["72"];
             $id25m = $arr4["73"];
              $id25n = $arr4["80"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
        
        $TotalExp = $id;
        $FirstLoginTime = $id2;
        $TotalDollorGet = $id3;
        $TodayGameTime = $id4;
        $TodayTCrystalLose = $id5;
        $Crystal = $id6;
        $TodayGoldGet = $id7;
        $TodayGoldLose = $id8;
        $Cracked = $id9;
        $WeaponList = $id10;
        $TodayExp = $id11;
        $TodayIapInfo = $id12;
        $cents1_099 = $id12a;
        $cents2_099 = $id12b;
        $new499cents1 = $id12c;
        $new499cents2 = $id12d;
        $new999cents1 = $id12e;
        $new999cents2 = $id12f;
        $new1999cents1 = $id12g;
        $new1999cents2 = $id12h;
        $new4999cents1 = $id12i;
        $new4999cents2 = $id12j;
        $Gold = $id13;
        $Level = $id14;
        $GameActiveTime = $id15;
        $TotalGoldGet = $id16;
        $UILastId = $id17;
        $HireoutSelfTimes = $id18;
        $TotalGameTime = $id19;
        $TodayTCrystalGet = $id20;
        $deviceid = $id21;
        $gamename = $id22;
        //$whatday = $id23;
        $createdate = $id24;
         $ChoosePointsUI = $id25a;
        $ShopUI_Weapon = $id25b;
        $ShopUI_Avatar = $id25c;
        $ShopUI_PowerUPS = $id25d;
        $ShopUI_Bank = $id25e;
        $BoostUI_Skill = $id25f;
        $TeamUI_Friend = $id25g;
        $TeamUI_MERC = $id25h;
        $MERC_UI = $id25i;
        $OptionUI = $id25j;
        $BattleUI_Pause = $id25k;
        $BattleUI_Item = $id25l;
        $BattleUI_Dead = $id25m;
        $ExchangeUI = $id25n;



        mysql_query("INSERT INTO comds_query (TotalExp, FirstLoginTime,FirstLogin,TotalDollorGet,TodayGameTime,TodayTCrystalLose,
                                        Crystal,TodayGoldGet,TodayGoldLose,Cracked,WeaponList,TodayExp,TodayIapInfo,
                                        Gold,Level,GameActiveTime,TotalGoldGet,UILastId,HireoutSelfTimes,TotalGameTime,
                                        TodayTCrystalGet,deviceid,gamename,createdate,date,
                                         099cents1,099cents2,new499cents1,new499cents2,new999cents1,
                                        new999cents2,new1999cents1,new1999cents2,new4999cents1,new4999cents2,ChoosePointsUI,ShopUI_Weapon,ShopUI_Avatar,ShopUI_PowerUPS,ShopUI_Bank,BoostUI_Skill,TeamUI_Friend,TeamUI_MERC,MERC_UI,
OptionUI,BattleUI_Pause,BattleUI_Item,BattleUI_Dead,ExchangeUI) 
                    VALUES('$TotalExp','$FirstLoginTime','$FirstLoginTime','$TotalDollorGet','$TodayGameTime','$TodayTCrystalLose','$Crystal','$TodayGoldGet','$TodayGoldLose','$Cracked','$WeaponList','$TodayExp',
                           '$TodayIapInfo','$Gold','$Level','$GameActiveTime','$TotalGoldGet','$UILastId','$HireoutSelfTimes','$TotalGameTime','$TodayTCrystalGet',
                           '$deviceid','$gamename','$createdate','$createdate',
                           '$cents1_099','$cents2_099','$new499cents1','$new499cents2','$new999cents1','$new999cents2','$new1999cents1',
                           '$new1999cents2','$new4999cents1','$new4999cents2','$ChoosePointsUI','$ShopUI_Weapon ','$ShopUI_Avatar ','$ShopUI_PowerUPS','$ShopUI_Bank ','$BoostUI_Skill','$TeamUI_Friend ','$TeamUI_MERC','$MERC_UI ',
'$OptionUI ','$BattleUI_Pause','$BattleUI_Item','$BattleUI_Dead ','$ExchangeUI')") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
